/**
 * Project: complex.thinkinjava
 * 
 * File Created at 2010-5-13
 * $Id$
 * 
 * Copyright 2008 Alibaba.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package no3;

/**
 * @description:转8.16进制
 * @author gaoliang
 * @date 2010-5-13
 * @version 1.0
 */
public class Test816 {
    public static void main(String[] args) {
        char hexDigits[] = { // 用来将字节转换成 16 进制表示的字符
                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c',
                        'd', 'e', 'f' };
        
        //取模运算   其实就是 n & (N-1) 
        byte a = 11 & 15;//取16的模(与上面的数组结合,即可转16进制)
        a = 11 & 7;//取8的模
        a = 11 & 9;//取10的模
        
        a = 11 & 1;//取2的模(即可判断奇偶数)
        
        //转16进制时,只要 7 0xf即可  0x开关的为16进制数
        //其中的0xf 写成15也可以(只是一种表示形式)
        char char16 = hexDigits[16 & 0xf];
        System.out.println(char16);
        
        //8进制数以0开头
        char char8 = hexDigits[16 & 07];
        System.out.println(char8);
        
    }
}
